package com.woniuxy.usercoachassemble.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniuxy.API.UserAPI;
import com.woniuxy.entityDTO.UserDTO;
import com.woniuxy.usercoachassemble.entity.Member;
import com.woniuxy.usercoachassemble.service.impl.MemberServiceImpl;
import org.example.Result;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MemberController implements UserAPI {
    @Autowired
    private MemberServiceImpl memberService;
    @Override
    public Result<UserDTO> selectUserScoreByUserId(int id) {
        QueryWrapper<Member> wrapper = new QueryWrapper<Member>();
        wrapper.eq("user_id",id);
        Member member=memberService.getOne(wrapper);
        UserDTO userDTO = new UserDTO();
        BeanUtils.copyProperties(member,userDTO);
        return new Result<UserDTO>(userDTO,200,"查询成功",true);
    }

    @Override
    public Result<UserDTO> updateUserScoreByUserId(int id, int Score) {
        QueryWrapper<Member> wrapper = new QueryWrapper<Member>();
        wrapper.eq("user_id",id);
        Member member= memberService.getOne(wrapper);
        member.setScore(Score);
        memberService.updateById(member);
        return Result.Success();
    }
}
